package iotwisp.school.api.controller.pc_admin.wx;

import iotwisp.base.cqrs.BusinessException;
import iotwisp.base.rest.JSONResultDTO;
import iotwisp.base.rest.RestBaseController;
import iotwisp.school.wx.command.GetAccessTokenSCmd;
import iotwisp.school.wx.entity.WxUser;
import iotwisp.school.wx.service.WxUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@Controller
@RequestMapping("/api/wx")
public class WxController extends RestBaseController {

    @Autowired
    private WxUserService wxUserService;

    @PutMapping(value = "/get_access_token")
    public ResponseEntity<JSONResultDTO> queryVaAccount(@RequestBody(required = false) GetAccessTokenSCmd cmd, HttpServletRequest request) throws BusinessException {

        initHeader(cmd, request);
        WxUser wxUser = wxUserService.getAccessToken(cmd);
        return ResponseEntity.ok(createSuccessResult(wxUser));
    }
}
